const api = getApp().globalData.api;
const imgUrl = getApp().globalData.imgUrl;

// common.js
function requestGet(opt) {
  // set token
  wx.request({
    method: opt.method || 'GET',
    url: api + opt.url,
    headers: {
      'content-type': 'application/json'
    },
    data: opt.data,
    success: function (res) {
      opt.success(res);
    }
  })
}

function requestPost(opt) {
  // set token
  wx.request({
    method: 'POST',
    url: api + opt.url,
    header: {
      'content-type': 'application/json'
    },
    data: opt.data,
    success: function (res) {
      opt.success(res);
    }
  })
}

function requestPut(opt) {
  // set token
  wx.request({
    method: 'PUT',
    url: api + opt.url,
    header: {
      'content-type': 'application/json'
    },
    data: opt.data,
    success: function (res) {
      opt.success(res);
    }
  })
}

function requestDelete(opt) {
  // set token
  wx.request({
    method: 'DELETE',
    url: api + opt.url,
    header: {
      'content-type': 'application/json'
    },
    data: opt.data,
    success: function (res) {
      opt.success(res);
    }
  })
}

module.exports = {
  requestPost: requestPost,
  requestGet: requestGet,
  requestPut: requestPut,
  requestDelete: requestDelete,
  api: api,
  imgUrl: imgUrl
}